package com.chris.service.impl;

import com.chris.domain.User;
import com.chris.repository.UserRepository;
import com.chris.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * Created by chris on 2019/2/2.
 */
@Service
@Transactional
public class UserServiceImpl implements UserService {

    // jpa 使用

    @Autowired
    private UserRepository userRepository;

    public User findUserById(Long id){
        return userRepository.findUserById(id);
    }

    @Override
    public User findById(Long id) {
        return  userRepository.findById(id).get();
    }


    // mybatis  使用
//    @Autowired
//    private UserMapper userMapper;
//
//    public Map findById(Long id){
//        return userMapper.findById(id);
//    }

    @Override
    public User findByUsername(String username) {
        System.out.println(userRepository);
        return userRepository.findByUsername(username);
    }


}
